﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WPFSkiaDragDemo
{
    /// <summary>
    /// 图元类型
    /// </summary>
    public enum ElementType
    {
        Circle,
        Rectangle,
        Triangle,
        Line,
        Text,
        FB,
    }
    /// <summary>
    /// 图元状态
    /// </summary>
    public enum ElementState
    {
        Normal,
        Selected,
        Dragging,
        Debug,
    }
    public enum DataBindType
    {
        IN,
        OUT,
        INOUT,
        OPERAND,//操作对象，
    }
    public class DataBindInfo
    {
        public string Name { get; set; } = string.Empty;
        /// <summary>
        /// 数据绑定类型,输入，输出，输入输出
        /// </summary>
        public DataBindType BindType { get; set; }
        /// <summary>
        /// 校验数据类型
        /// </summary>
        public string ValueType { get; set; } = string.Empty;
        public string Symbol { get; set; } = string.Empty;

    }
    public class ElementInfo
    {
        public string Name { set; get; } = string.Empty;
        public ElementType ElementType { set; get; }
        public float Offset_X { set; get; } = 0;
        public float Offset_Y { set; get; } = 0;
        public List<DataBindInfo> DataBindInfos { set; get; } = new List<DataBindInfo>();

        /// <summary>
        /// 返回所有的输入
        /// </summary>
        /// <returns></returns>
        public List<DataBindInfo> GetIN()
        {
            return this.DataBindInfos.Where(DataBindInfos => DataBindInfos.BindType==DataBindType.IN).ToList();
        }
        public List<DataBindInfo> GetINOUT()
        {
            return this.DataBindInfos.Where(DataBindInfos => DataBindInfos.BindType==DataBindType.INOUT).ToList();
        }
        /// <summary>
        /// 返回所有的输出
        /// </summary>
        /// <returns></returns>
        public List<DataBindInfo> GetOUT()
        {
            return this.DataBindInfos.Where(DataBindInfos => DataBindInfos.BindType == DataBindType.OUT).ToList();
        }
        /// <summary>
        /// 有些可能为空，操作对象，最顶上的绑定
        /// </summary>
        /// <returns></returns>
        public DataBindInfo? GetDataBindOPERAND()
        {
            return this.DataBindInfos.FirstOrDefault(DataBindInfos => DataBindInfos.BindType == DataBindType.OPERAND);
        }
        /// <summary>
        /// 根据名字返回数据绑定信息
        /// </summary>
        /// <returns></returns>
        public DataBindInfo? GetDataBindInfoByName(string name)
        {
            return this.DataBindInfos.FirstOrDefault(DataBindInfos => DataBindInfos.Name == name);
        }

        /// <summary>
        /// 返回输入或者输出的最多，用来绘图
        /// </summary>
        /// <returns></returns>
        public int GetMaxHight()
        {
            int InCount=GetIN().Count;
            int InoutCount=GetINOUT().Count;
            int OutCount=GetOUT().Count;
            return Math.Max(InCount+InoutCount, OutCount);
        }
    }
}
